package cn.jaychang.demo5.common.util;

import cn.jaychang.demo5.common.model.Result;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jaychang
 * @since 2024/5/22
 **/
public class ResponseUtil {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static void result(HttpServletResponse response, Result result) throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        ServletOutputStream out = response.getOutputStream();
        out.write(objectMapper.writeValueAsString(result).getBytes("UTF-8"));
        out.flush();
        out.close();
    }
}
